package com.example.demo.test.selenium;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.Select;
import org.openqa.selenium.support.ui.WebDriverWait;

public  class SeleniumHelper {
    public static WebDriver driver;
    public static WebDriverWait wait;
    
    public static void init() {
        driver = Chrome.getOneDriver();
        wait = new WebDriverWait(driver, 20);
    }

    public static void quit() {
        driver.quit();
    }    public static void back() {
        driver.navigate().back();
    }
    public static void waitByPath(String xpath) throws Exception {
        By xpath1 = By.xpath(xpath);
        wait.until(ExpectedConditions.presenceOfElementLocated(xpath1));
    }

    public static void waitAndClickByPath(String xpath) {
        By xpath1 = By.xpath(xpath);
        wait.until(ExpectedConditions.presenceOfElementLocated(xpath1));
        driver.findElement(xpath1).click();
    }

    public static void findByIdAndClearSend(String id, String text) {
        WebElement element = driver.findElement(By.id(id));
        element.clear();
        element.sendKeys(text);
    }

    public static void findByIdAndSelectByIndex(String id, int index) {
        new Select(driver.findElement(By.id(id))).selectByIndex(index);
    }

    public static void findByIdAndClick(String id) {
        driver.findElement(By.id(id)).click();
    }


}
